package com.oujia.cloud.cloudcommon.util;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PageHelper<T> {
    //当前页
    private Integer pageNum = 1;
    //每页的数量
    private Integer pageSize = 10;

    //总记录数
    private Integer total = 0;
    //总页数
    private int pages = 1;
    //分数
    private  Double score = 0.0;

    //结果集
    private List<T> list = new ArrayList<>();

    //是否为第一页
    private boolean isFirstPage = true;
    //是否为最后一页
    private boolean isLastPage = false;


    public PageHelper(Integer pageNum, Integer pageSize, Integer total, List list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        if (total > 0) {
            this.pages = total / pageSize;
            if (this.pages <= 0) {
                this.pages = 1;
            }
        }
        if (list != null) {
            if (pageNum * pageSize >= total) {
                this.isLastPage = true;
            }
        }
        if (pageNum > 1) {
            this.isFirstPage = false;
        }

    }

    public PageHelper(Integer total, List list) {
        this.total = total;
        this.list = list;
        this.isLastPage = true;
    }

    public PageHelper(Integer pageNum, Integer pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.isLastPage = true;
    }

}
